package servlet;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet("/regist")
public class RegistServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("RegistServlet.service()");

        String username=request.getParameter("username");
        String password=request.getParameter("password");
        String phone=request.getParameter("phone");

        if("abc".equals(username)){
            request.setAttribute("message","用户名已存在");
//            request.getRequestDispatcher("/regist.jsp").forward(request,response);
            request.getRequestDispatcher("/jquery/regist.jsp").forward(request,response);
            return;
        }

        System.out.println("注册..."+username+" "+password+" "+phone);
        response.sendRedirect(request.getContextPath()+"/index.jsp");

    }
}
